<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>欢迎来到防绿帽系统</title>

    <!-- Bootstrap core CSS -->
    <link href="/bootstrap-4.0.0-dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="/stylesheets/login.css" rel="stylesheet">
    <script type="text/javascript" src="/javascripts/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="/javascripts/jquery.cookie.js"></script>
    <script type="text/javascript" src="/javascripts/login.js"></script>
</head>

<body class="text-center">
<div class="form-signin">
    <img class="mb-4" src="/images/logo.png" alt="" width="100" height="100">
    <h1 class="h3 mb-3 font-weight-normal">欢迎来到防绿帽系统</h1>
    <input type="email" id="inputAccount" class="form-control" placeholder="请输入你的账号" required autofocus>
    <input type="password" id="inputPassword" class="form-control" placeholder="请输入密码" required>
    <div class="alert alert-warning hidden" id="hud" >登录失败</div>
    <button class="btn btn-lg btn-primary btn-success btn-block"  id="loginBtn">登录</button>
    <button class="btn btn-lg btn-primary btn-success btn-block" id="registerBtn">注册</button>
    <p class="mt-5 mb-3 text-muted">© Wbqqqq</p>
</div>
</body>
</html>


<script type="text/javascript">

    $('#registerBtn').click(function () {

        window.location.href='/register'
    });


    $('#loginBtn').click(function () {
        let inputAccount = $("#inputAccount").val()
        let inputPassword = $("#inputPassword").val()
        if(!inputAccount.length) {
            $("#hud").text("账号不能为空");
            $("#hud").show()
            return
        }else {
            $("#hud").hide()
        }

        if(!inputPassword.length){
            $("#hud").text("密码不能为空");
            $("#hud").show()
            return
        }else {
            $("#hud").hide()
        }

        login(inputAccount,inputPassword,(res)=>{
            console.log('接收到了回吊')
            console.log(res)
            if(res.code == 1){
                $.cookie("userToken",'Bearer ' + res.data.token);
                window.location.href='/'
            }else {
                $("#hud").text(res.msg);
                $("#hud").show()
            }
        });



    });

</script>



